<include file="./Application/Common/View/pageheader.html" />

<div class="row">
<div class="col-sm-12">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>添加医生</h5>
            <ol class="breadcrumb pull-right">
                <li>
                    <a href="{:U('Admin/Doctors/index')}"><strong>返回上一页</strong></a>
                </li>
            </ol>
        </div>
        <div class="ibox-content">		
			<form class="form-horizontal col-sm-12" action="{:U('Admin/Doctors/addDoctors')}" method="POST">
				<div class="col-sm-8">	                
					<div class="form-group">
						<label class="col-sm-3 control-label">医院</label>
						<div class="col-sm-7">
							<select class="form-control" name="hospital_id" id="hospital" onchange="javascript:getKeshi();">
								<foreach name="Hospital" item="vo">
	                            <option value="{$vo['id']}">{$vo['name']}</option>
	                            </foreach> 
							</select>
						</div>
					</div>
					<div class="form-group">
	                    <label class="col-sm-3 control-label">科室</label>
	                    <div class="col-sm-7">
							<select class="form-control" name="keshi_id" id="keshi">
								
							</select>
						</div>
	                </div>
					<div class="form-group">
						<label class="col-sm-3 control-label">医生电话</label>
						<div class="col-sm-7">
							<input name="phone" class='form-control' placeholder="科室医生电话" >
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">密码</label>
						<div class="col-sm-7">
							<input name="password" class='form-control' placeholder="密码">
						</div>
					</div>					
				</div>
				<div class="clearfix"></div>
				<div class="from-group">
					<button class='btn btn-success'>添加</button>
				</div>
            </form>
            <div class="clearfix"></div>
		</div>
    </div>
</div>

<include file="./Application/Common/View/pagefooter.html" />
<script>
	$(function(){
		var hospital_id = $("#hospital option:first").val();
		return getdefaultKeshi(hospital_id);
	})
	
	function getdefaultKeshi(hospital_id) {
		$.get("/Admin/Doctors/ajaxKeshi", { hospital_id: hospital_id },
			function(data){
				if(data == null) {
					$("#keshi").html('null');
					return true;
				}
				return rendKeshi(data);
			}
		);
	}

	function getKeshi() {
		var hospital_id = $("#hospital option:selected").val();
		$.get("/Admin/Doctors/ajaxKeshi", { hospital_id: hospital_id },
			function(data){
				if(data == null) {
					$("#keshi").html('null');
					return true;
				}
				return rendKeshi(data);
			}
		);
	}
	
	function rendKeshi(data) {
		//console.log(data);
		var optionHtml = '';
		var html='';
		var count = data.length;
		var i;
		for(i=0; i<count; i++)
		{
			optionHtml = '<option value="'+data[i].keshi_id+'">'+data[i].name+'</option>'; 
			html = html + optionHtml;
		}
		$("#keshi").html(html);
		
	}
</script>
